package com.share.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String path = req.getContextPath();
        String basepath = req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+path+"/";
        System.out.println("path"+path);
        System.out.println("basepath"+basepath);
        //
        req.setCharacterEncoding("UTF-8");
        System.out.println("处理get请求1");
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/html;charset=utf-8");
        out.println("<strong> hello servlet!！！</strong> <br>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("处理post请求2");
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/html;charset=utf-8");
        out.println("<strong> hello servlet!！！</strong> <br>");
    }
}
